<?php
/* 
 * 点歌操作类
 * 程序编写：pennyowen/pepsi.zh
 * 联系邮箱：penyowen#gmail.com/pepsi.zh#gmail.com
 * 修改时间：2008-9-30
 */
if (!defined('IN_SITE')){ die('Hacking attempt!'); }
interface BlessingDbInter{
	### 功能：提交一个点歌记录  参数：$post 提交的内容 #####
    function submitRecord($post);
    ### 功能：删除点歌记录  参数：$id 记录id，可以是数组，也可以是当id #####
    function deleteRecord($id);
	### 功能：物理删除点歌记录  参数：$id 记录id #####
	function physicalDeleteRecord($id);
    ### 功能：得到一条点歌记录  参数：$id 记录id #####
    function getOneRecord($id);
    ### 功能：设置该记录为处理完的点歌记录  参数：$id 记录id #####
    function dealBlessing($id);
}
class blessing implements BlessingDbInter
{
	public  $error = array();
	function submitRecord($post){
		global $dbconn,$dbtable;
		$post = acrossTrim($post);
		$flag = true;
		if (strlen($post[Bfromname]) < 1){
			$flag = false;
			$this->error[e_Bfromname] = '发布人不能为空';
		}
		if (empty($post[Btoname])){
			$flag = false;
			$this->error[e_Btoname] = '接收人不能为空';
		}
		if (empty($post[Bsendsong])){
			$flag = false;
			$this->error[e_Bsendsong] = '歌曲不能为空';
		}
		if (empty($post[Bcontect])){
			$flag = false;
			$this->error[e_Bcontect] = '祝福不能为空';
		}
		if ($flag){
			$post[Bupdate] = date("Y-m-d H:i:s");
			if ($post[Bid]){
				return $dbconn->Query_update($post,$dbtable->blessing,array('Bid'=>$post[Bid]));
			}else {
				return $dbconn->Query_adate($post,$dbtable->blessing);
			}
		}else {
			return false;
		}
	}
	function physicalDeleteRecord($id)
	{
		global $dbconn,$dbtable;
		if ($id<1)return false;
		$query = "DELETE FROM ".$dbtable->blessing." WHERE `Bid` ='".$id."' ";
		$dbconn->Query($query);
		return $dbconn->returnAffected();
	}

	function deleteRecord($id){
		global $dbconn,$dbtable;
		if (empty($id)){ return false ;}
		if (is_array($id)){
			$where = "where Bid in(".implode(',',$id).")";
		}else {
			$where = "where Bid=$id";
		}
		return $dbconn->Query_update(array('Bdelete'=>'y'),$dbtable->blessing,$where);
	}
	function getOneRecord($id){
		global $dbconn,$dbtable;
		if (empty($id)){ return false ;}
		$query = "select * from ".$dbtable->blessing." where Bid=$id limit 1";
		return $dbconn->Getonerecord($query);
	}
	function dealBlessing($id){
		global $dbconn,$dbtable;
		if (empty($id)){ return false ;}
		return $dbconn->Query_update(array('Bdeal'=>'y'),$dbtable->blessing,array('Bid'=>$id));
	}
}
?>